<template>
	<div class="content-page">
		<div class="content-nav">
			<div class="breadcrumb">
				{{form.categoryId?'修改分类':'添加分类'}}
			</div>
			<div class="operation-nav">
				<el-button type="primary" @click="goBackPage" size="small" icon="arrow-left">返回列表</el-button>
			</div>
		</div>
		<div class="content-main">
			<el-form ref="form" :model="form" label-width="80px">
				<el-form-item label="分类名称">
					<el-input v-model="form.category"></el-input>
				</el-form-item>
				<el-form-item label="分类状态">
					<el-radio-group v-model="form.status">
						<el-radio :label="1">启动</el-radio>
						<el-radio :label="0">关闭</el-radio>
					</el-radio-group>
				</el-form-item>
				<el-form-item label="分类排序">
					<el-input-number v-model="form.sorting" :min="0" ></el-input-number>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" @click="onSubmit">保存</el-button>
					<el-button @click="goBackPage">取消</el-button>
				</el-form-item>
			</el-form>
		</div>
	</div>
</template>

<script>
	import {
		addCategory
	} from '@/api/permission'
	export default {
		data() {
			return {
				pageLoading: false,
				form: {
					categoryId: '',
					category: '',
					status: 1,
					sorting: ''
				}
			}
		},
		methods: {
			goBackPage() {
				this.$router.go(-1);
			},
			onSubmit(){
				let self = this
				let form = self.form
				form['sorting'] = Number(form['sorting'])
				addCategory(form).then(res=>{
					self.goBackPage()
				})
			},
			getInfo() {
				if (this.infoForm.id <= 0) {
					return false
				}

				//加载品牌详情
				let that = this
				this.axios.get('http://127.0.0.1:8360/admin/brand/info', {
					params: {
						id: that.infoForm.id
					}
				}).then((response) => {
					console.log(response.data);
					let resInfo = response.data.data;
					that.infoForm = resInfo;
					this.pageLoading = false;
				})
			}

		},
		components: {},
		mounted() {
			let self = this
			console.log(this.$route.params)
			if(this.$route.params.data){
				let data = JSON.parse(self.$route.params.data)
				for(let key in self.form){
					self.form[key] = data[key]
				}
			}
			// this.infoForm.id = this.$route.query.id || 0;
			// this.getInfo();
		}
	}
</script>

<style>

</style>
